#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 1; i <= n; ++i)
const int N = 1e5 + 7;
int t, n, m, L, V, sum[1000007], a[N], v[N], d[N], p[N], ans, cnt;
pair<int, int> z[N];
int up(int a, int b)
{
    if (a < 0)
        a = -a, b = -b;
    if (a % b && b < 0)
        return a / b - 1;
    else
        return a / b;
}
int down(int a, int b)
{
    if (a < 0)
        a = -a, b = -b;
    if (a % b && b > 0)
        return a / b;
    else
        return a / b - 1;
}
int src(int num)
{
    int l = 1, r = m, ans;
    while (l <= r)
    {
        int mid = (l + r) / 2;
        if (p[mid] <= num)
        {
            ans = mid;
            l = mid + 1;
        }
        else
            r = mid - 1;
    }
    return ans;
}
bool cmp(pair<int, int> a, pair<int, int> b)
{
    if (a.second == b.second)
        return a.first < b.first;
    else
        return a.second < b.second;
}
signed main()
{
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    cin >> t;
    while (t--)
    {
        memset(sum, 0, sizeof sum);
        ans = cnt = 0;
        cin >> n >> m >> L >> V;
        int v2 = V * V;
        rep(i, n)
            cin >> d[i] >> v[i] >> a[i];
        rep(i, m)
        {
            cin >> p[i];
            ++sum[p[i]];
        }
        sort(p + 1, p + m + 1);
        rep(i, 1e6)
            sum[i] += sum[i - 1];
        rep(i, n)
        {
            double l, r;
            if (a[i] == 0)
            {
                if (v[i] > V && sum[L] - sum[d[i] - 1] > 0)
                {
                    ++ans;
                    z[++cnt] = {d[i] - 1, L};
                }
            }
            else if (a[i] > 0)
            {
                int des = up(v2 - v[i] * v[i], 2 * a[i]);
                des += d[i];
                if (L >= des && sum[L] - sum[des] > 0)
                {
                    ++ans;
                    z[++cnt] = {des, L};
                }
            }
            else if (a[i] < 0)
            {
                int des = down(v2 - v[i] * v[i], 2 * a[i]);
                des += d[i];
                if (des >= d[i] && sum[des] - sum[d[i] - 1] > 0)
                {
                    ++ans;
                    z[++cnt] = {d[i] - 1, des};
                }
            }
        }
        sort(z + 1, z + cnt + 1, cmp);
        int now, ans2 = 0;
        rep(i, cnt)
        {
            if (p[now] > z[i].first && p[now] <= z[i].second)
                continue;
            else
            {
                now = src(z[i].second);
                ++ans2;
            }
        }
        cout << ans << ' ' << m - ans2 << endl;
    }
    return 0;
}
